package com.haochang.chunkvod.controller.fragment.order;

import java.util.ArrayList;
import java.util.List;

import com.haochang.base.BaseFragment;
import com.haochang.base.BaseListView;
import com.haochang.chunkvod.R;
import com.haochang.chunkvod.app.utils.CollectionUtils;
import com.haochang.chunkvod.app.utils.TimeUtils;
import com.haochang.chunkvod.controller.adapter.base.BaseAdapterHelper;
import com.haochang.chunkvod.controller.adapter.base.QuickAdapter;
import com.haochang.chunkvod.model.service.ServiceData;
import com.haochang.chunkvod.model.service.ServiceInfo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

/**
 * @author qintao
 *         created at 2016/6/13 10:38
 *         服务已处理--与服务新增公用布局
 */

public class ServiceDoneFragment extends BaseFragment
{
	private BaseListView listView;
	private QuickAdapter dataAdapter;
	private List<ServiceInfo> infoList = new ArrayList<ServiceInfo>();
	private ServiceData serviceData;
	private String roomId;

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
	{
		return inflater.inflate(R.layout.fragment_add_service, container, false);
	}

	@Override
	public void onActivityCreated(@Nullable Bundle savedInstanceState)
	{
		super.onActivityCreated(savedInstanceState);
		initView();
		initData();
	}

	private void initData()
	{
		serviceData = new ServiceData(getActivity());
		serviceData.requestService(roomId, "1", new ServiceData.IRequestServiceListener()
		{

			@Override
			public void onRequestSuccess(List<ServiceInfo> list)
			{
				if (!CollectionUtils.isEmpty(list))
				{
					infoList.clear();
					infoList.addAll(list);
					dataAdapter.replaceAll(infoList);
				}
			}
		});
	}

	private void initView()
	{
		listView = (BaseListView) findViewById(R.id.listView);
		findViewById(R.id.lay_done_title).setVisibility(View.VISIBLE);
		dataAdapter = new QuickAdapter<ServiceInfo>(getActivity(), R.layout.item_service_done_fragment_layout, infoList)
		{

			@Override
			protected void convert(BaseAdapterHelper helper, ServiceInfo item)
			{

				helper.setText(R.id.tv_foodName, item.getService_content());
				helper.setText(R.id.tv_num, item.getAmount() + "");
				helper.setText(R.id.tv_time, TimeUtils.getMinutesString(item.getUpdate_time()));
			}
		};
		listView.setAdapter(dataAdapter);
	}
}
